package com.wwj.gulimall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.wwj.gulimall.product.service.BrandService;
import com.wwj.gulimall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wwj.common.utils.PageUtils;
import com.wwj.common.utils.Query;

import com.wwj.gulimall.product.dao.CategoryBrandRelationDao;
import com.wwj.gulimall.product.entity.CategoryBrandRelationEntity;
import com.wwj.gulimall.product.service.CategoryBrandRelationService;
import org.springframework.web.bind.annotation.RequestParam;


@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CategoryBrandRelationEntity> page = this.page(
                new Query<CategoryBrandRelationEntity>().getPage(params),
                new QueryWrapper<CategoryBrandRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<CategoryBrandRelationEntity> queryByBrandId(Map<String, Object> params) {
        String brandId = (String) params.get("brandId");
        HashMap<String, Object> map = new HashMap<>();
        map.put("brand_id", brandId);
        return baseMapper.selectByMap(map);
    }

    @Override
    public void updateBrand(Long brandId, String name) {
        LambdaUpdateWrapper<CategoryBrandRelationEntity> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(CategoryBrandRelationEntity::getBrandName,name)
                .eq(CategoryBrandRelationEntity::getBrandId,brandId);
        this.update(wrapper);
    }

    @Override
    public void updateCatelog(Long catId, String name) {
        LambdaUpdateWrapper<CategoryBrandRelationEntity> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(CategoryBrandRelationEntity::getCatelogName,name)
                .eq(CategoryBrandRelationEntity::getCatelogId,catId);
        this.update(wrapper);
    }

    @Override
    public List<CategoryBrandRelationEntity> queryByCatId(Long catId) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("catelog_id", catId);
        return baseMapper.selectByMap(map);
    }


}